<template>
  <div class="recommended">
    <div class="recommended-header">
      <div class="search-input-con">
        <SearchInput />
      </div>
      <div class="label-manage-entry">
        <div class="label-manage-entry__icon iconfont icon-shezhi"></div>
        <div class="label-manage-entry__text">标签</div>
      </div>
    </div>
    <div class="recommended-nav">
      <Nav :currentCategoryIndex="3" />
    </div>
    <div class="recommended-item">
      <div class="items" v-for="article in data">
        <div :key="article.article_id" class="articel_content" @click="goto(article.article_id)">
          <div class="auther_name">{{article.auther_name}}</div>
           <div class="article_title"><p>{{article.title}}</p></div>
           <div class="article_brief"><p>{{ article.brief_content }}</p></div>
           <hr />
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import SearchInput from '../../../../components/search-input/index.vue';
import Nav from './components/nav/index.vue';
import useRecommendBe from './useRecommendBe.ts'
import { useRouter } from 'vue-router'

export default defineComponent({
  components: {
    SearchInput,
    Nav,
  },
  setup () {
    const router = useRouter()
    let data = ref([])
    useRecommendBe(20).then(res => {
      console.log(res)
      for(let v of res) {
        // console.log(v);
        v.article_info.auther_name = v.author_user_info.user_name
        data.value.push(v.article_info)
        // console.log(v.article_info)
      }
    })
    const goto = id => {
      // console.log(id)
      router.push("/post/" + id)
    }
    return {
      data,
      goto
    }
  }
})
</script>

<style scoped lang="less">

.recommended-item {
  background-color: #fff;
  margin-top: .5rem;
}

.articel_content {
  position: relative;
  cursor: pointer;
  padding: 12px 20px 0;
}

.recommended {
  &-header {
    display: flex;
    align-items: center;
    padding: 20 * @unit 50 * @unit;
    background-color: @white;
    .search-input-con {
      flex: 1;
      margin-right: 25 * @unit;
    }
    .label-manage-entry {
      display: flex;
      align-items: center;
      flex-shrink: 0;
      flex-grow: 0;
      color: @secondary-text-color;
      &__icon {
        margin-right: 10 * @unit;
      }
    }
  }
}

.auther_name {
  font-size: 14px;
  font-weight: 200;
  margin-top: 10px;
  margin-bottom: 15px;
}

.article_title {
  font-weight: 600;
  
  margin-bottom: 10px;
}

.article_brief {
  font-size: 14px;
  line-height: 22px;
  margin-bottom: 14px;
}
</style>